<!--
 * @Author: 姜宇航
 * @Date: 2022-08-02 16:49:51
 * @LastEditors: 姜宇航
 * @LastEditTime: 2022-08-03 17:18:28
 * @FilePath: /iview-admin-grid/src/view/community-demographics/index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div>
    <Row>
      <Col span="10" offset="1"  align="center">
        <Card >
          <!-- <p slot="title" v-if="this.$store.state.user.severUserInfo.company_code != 'LM'" style="text-align: center">小区人口总数</p> -->
          <p slot="title" style="text-align: center">小区车辆总数</p>
          <h2 style="text-align: center">{{ personSum }}</h2>
        </Card>
      </Col>
      <!-- <Col span="10" offset="2" align="center">
        <Card style="text-align: center">
          <p slot="title" v-if="this.$store.state.user.severUserInfo.company_code === 'LM'">沈阳市全科社工资格总数</p>
          <p slot="title" v-if="this.$store.state.user.severUserInfo.company_code != 'LM'">{{ this.$store.state.user.severUserInfo.company_name }}全科社工资格总数</p>
          <h2 style="text-align: center">{{ quanKePersonnel }}</h2>
        </Card>
      </Col> -->
    </Row>
    <Card style="margin-top: 50px;">
      <Row>
        <Col span="12">
          <person-sum-pie-echart :width="echartWidth2" :height="400" ref="echart2"></person-sum-pie-echart>
        </Col>
        <Col span="12">
          <person-sum-bar-echart :width="echartWidth1" :height="400" ref="echart1"></person-sum-bar-echart>
        </Col>
      </Row>
    </Card>
  </div>
</template>

<script>
import { getQuanKePersonnel, carGroupCounts } from '@/api/eventlist'
import PersonSumBarEchart from './compoments/person-sum-bar-echart'
import PersonSumPieEchart from './compoments/person-sum-pie-echart'
export default {
  name: 'mainv4',
  components: {
    PersonSumBarEchart,
    PersonSumPieEchart
  },
  data () {
    return {
      echartWidth1: (document.documentElement.clientWidth - 300) / 2,
      echartWidth2: (document.documentElement.clientWidth - 300) / 2,
      dataInfo: {},
      personSum: 0,
      quanKePersonnel: 0
    }
  },
  computed: {},
  methods: {
    init () {
      // perGroupCounts().then(res => {
      //   console.log('res', res)
      // })
      carGroupCounts().then(ret => {
        if (ret.data.errcode === 0) {
          this.dataInfo = ret.data.data
          let sum = 0
          this.dataInfo.forEach(function (temp, index) {
            sum = sum + temp.counts
          })
          this.personSum = sum
          this.$refs.echart1.chart(this.dataInfo)
          this.$refs.echart2.chart(this.dataInfo)
        } else {
          this.$Notice.error({
            title: '查询失败',
            desc: ret.data.errmsg
          })
        }
      })
    },
    getQuanKePersonnel () {
      getQuanKePersonnel().then(res => {
        if (res.data.errcode === 0) {
          this.quanKePersonnel = res.data.data.sum
        }
      })
    }
  },
  mounted () {
    this.init()
    this.getQuanKePersonnel()
    console.log(this.$store.state.user.severUserInfo)
  },
  watch: {
  }
}
</script>
